package com.ybzl.gateway.config;

import com.google.common.util.concurrent.ThreadFactoryBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.*;

@Configuration
public class LocationThreadPoolConfig {

    @Bean
    public ThreadPoolExecutor threadPoolExecutor() {
        int corePoolSize = Runtime.getRuntime().availableProcessors() * 2;
        int maxPoolSize = corePoolSize * 3;
        return new ThreadPoolExecutor(corePoolSize, maxPoolSize
                , 60
                , TimeUnit.SECONDS
                , new SynchronousQueue<>()
                , new ThreadFactoryBuilder().setNameFormat("IoT-Gateway-Worker-%d").build()
                , new ThreadPoolExecutor.AbortPolicy());
    }

}
